<?php
/**
 * Created by PhpStorm.
 * User: yangyou
 * Date: 2018/12/3 0003
 * Time: 09:39
 */

namespace app\index\controller;

use app\index\model\Cases;
use app\index\model\Designer;
use app\index\model\Config;
use app\index\model\Drawing;
use app\index\model\Information;
use app\index\model\InformationKeyword;

class Team extends Base
{
    /**
     * Author:yang you
     * Time:2018-11-15 10:00:43
     * Describe:团队列表
     * @return \think\response\View
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function teamlist()
    {
        $team_id = input("id/d");
        $designer = new Designer();
        $config = new Config();
        $cases = new Cases();
        $information = new Information();
        $designerList = $designer->designerList($team_id);//设计师列表
        $designerType = $config->designerType();//设计师种类
        //右边案例推荐
        $rightCase = $cases->leftCaseList();
        //热门标签
        $hotTag =  $information->randKeywordInfo();
        //右侧16篇文章
        $informationList =  $information->informationList($classification_id = "",$limit = "12",$left="6",$center="12");

        return view('team/teamlist',[
            'designerList' => $designerList,
            'designerType' =>$designerType,
            'page' => $designerList->render(),
            'rightCase' =>$rightCase,
            'hotTag' =>$hotTag,
            'informationList' =>$informationList,
            ]);
    }
    /**
     * Author:yang you
     * Time:2018-11-15 10:00:43
     * Describe:设计师信息
     * @return \think\response\View
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function designerInfo()
    {
        $designer_id = input("id/d");
        $designer = new Designer();
        $drawing = new Drawing();
        $config = new Config();
        $recentDrawing = [];
        $designerInfo = $designer->info($designer_id);//设计师列表
        if(empty($designerInfo)){
            abort(404,'页面不存在');
        }
        //设计师代表作品
        $representative_works = $designerInfo['representative_works'];
        if(!empty($representative_works)){
            //字符串处理方便截取,获得图纸ID
            $representative_works = substr($representative_works,1);
            $representative_works = substr($representative_works,0,strlen($representative_works)-1);
            $drawingId = explode('][',$representative_works);
            foreach ($drawingId as $key=>$val){
                $drawingInfo[$key] = $drawing->info($val);
            }
            $this->assign("drawingInfo",$drawingInfo);
        }
        //设计师最近项目
        $designer_design_case = $designerInfo['designer_design_case'];
        if(!empty($designer_design_case)){
            $designer_design_case = ltrim($designer_design_case,"[");
            $designer_design_case = rtrim($designer_design_case,"]");
            $designer_design_case =explode("][",$designer_design_case);
            foreach ($designer_design_case as $key=>$val){
                if($key>=25){
                    break;
                }else{
                    $recentDrawing[$key/5][$key] = $drawing->dataInfo("no", $val);
                }
            }
        }
        $config_info = $config->drawingList();//配置参数的ID
        $seo_Info['seo_title'] = $designerInfo['designer_level_name'].$designerInfo['designer_name'].'-别墅工场';
        $seo_Info['seo_keyword'] = '别墅设计 '.$designerInfo['designer_level_name'].'从业年限'.$designerInfo['years'];
        $seo_Info['seo_description'] = '';
        return view('team/designerInfo',[
            'designerInfo' => $designerInfo,
            'config_info' => $config_info,
            'recentDrawing' => $recentDrawing,
            'seo_Info' => $seo_Info
        ]);

    }

}